
package com.ukao.steward.pesenter.valetRunners;

import com.ukao.steward.base.BasePresenter;
import com.ukao.steward.bean.OrderInfoBean;
import com.ukao.steward.bean.StoreBean;
import com.ukao.steward.bean.serviceTimeBean;
import com.ukao.steward.consts.Constant;
import com.ukao.steward.consts.SaveParams;
import com.ukao.steward.retrofit.ApiCallback;
import com.ukao.steward.view.valetRunners.OrderSubmitView;

import java.util.HashMap;
import java.util.List;

/**
 * Created by ukaodev on 2017/6/28.
 */

public class OrderSubmitPesenter extends BasePresenter<OrderSubmitView> {


    public OrderSubmitPesenter(OrderSubmitView view) {
        attachView(view);
    }

    /**
     * 店铺列表
     */
    public void storelist() {
      mvpView.showLoading();
        HashMap mHashMap = new HashMap<String, String>();
        mHashMap.put("accessToken", SaveParams.getToken());
        addSubscription(apiStores.storelist(Constant.createParameter(mHashMap)),
                new ApiCallback<StoreBean>() {


                    @Override
                    public void onSuccess(StoreBean model) {

                        if (model.getHttpCode() == 200) {
                            List<StoreBean> mStoreData = model.getData();
                            mvpView.storelistSucceed(mStoreData);


                        }

                    }

                    @Override
                    public void onFinish() {
                        mvpView.hideLoading();

                    }
                });
    }


    /**
     * 新增订单
     */
    public void orderAdd( HashMap mHashMap ) {
        mvpView.showLoading();
        addSubscription(apiStores.storeCreateOrder(Constant.createParameter(mHashMap)),
                new ApiCallback<OrderInfoBean>() {
                    @Override
                    public void onSuccess(OrderInfoBean model) {

                        if (model.getHttpCode() == 200) {
                            mvpView.orderAddSucceed(model.getData());

                        }else{
                            mvpView.showError(model.getMsg());
                        }

                    }

                    @Override
                    public void onFinish() {
                        mvpView.hideLoading();

                    }
                });
    }

    /**
     *服务时间
     */
    public void serviceTime(   ) {
        mvpView.showLoading();
        HashMap mHashMap = new HashMap<String, String>();
        mHashMap.put("accessToken", SaveParams.getToken());
        addSubscription(apiStores.serviceTime(Constant.createParameter(mHashMap)),
                new ApiCallback<serviceTimeBean>() {
                    @Override
                    public void onSuccess(serviceTimeBean model) {
                        if (model.getHttpCode() == 200) {
                            mvpView.serviceTimeSucceed(model.getData().getList());
                        }else{
                            mvpView.showError(model.getMsg());
                        }

                    }

                    @Override
                    public void onFinish() {
                        mvpView.hideLoading();

                    }
                });
    }






}
